// zh_jdgjb/pages/fapiao/fapiao.js
var siteinfo = require('../../../siteinfo.js'),
	app = getApp()

Page({
	data: {
		arrays: ['暂无星级(经济型)', '三星级', '四星级', '五星级'],
		index: 0,
		inde: 0,
		prompt: !1,
		choice: !0,
		getmsg: '获取验证码',
		interval: 'interval2',
		num: 0,
		store_num: 1
	},
	onLoad: function (t) {
		var e = this
		app.getSystem(e), app.getUrl(e)
		wx.getStorageSync('openid')
		var a = wx.getStorageSync('users').id
		e.setData({
			user_id: a,
			order_id: t.order_id,
			money: t.money
		})
	},
	choose_address: function (t) {
		var a = this
		wx.chooseLocation({
			success: function (t) {
				var e = t.latitude + ',' + t.longitude
				a.setData({
					address: t.address,
					latitude: e
				})
			}
		})
	},
	bindPickerChanges: function (t) {
		this.setData({
			index: t.detail.value
		})
	},
	choose: function (t) {
		var a = this,
			n = siteinfo.siteroot,
			i = siteinfo.uniacid,
			o = t.currentTarget.dataset.id
		wx.chooseImage({
			count: 1,
			sizeType: ['original', 'compressed'],
			sourceType: ['album', 'camera'],
			success: function (t) {
				var e = t.tempFilePaths[0]
				wx.uploadFile({
					url: n + '?i=' + i + '&c=entry&a=wxapp&do=upload&m=zh_jdgjb',
					filePath: e,
					name: 'upfile',
					formData: {},
					success: function (t) {
						1 == o
							? a.setData({
									upload_one: t.data
							  })
							: 2 == o
							? a.setData({
									upload_two: t.data
							  })
							: 3 == o &&
							  a.setData({
									upload_three: t.data
							  })
					},
					fail: function (t) {}
				})
			}
		})
	},
	user_tel: function (t) {
		this.setData({
			phone: t.detail.value
		})
	},

	formSubmit: function (t) {
		var e = this,
			a = e.data.store_num,
			n = t.detail.value.company,
			i = t.detail.value.address,
			mail = t.detail.value.mail,
			nssb = t.detail.value.nssb
		var s = t.detail.value.name,
			u = t.detail.value.phone,
			r = t.detail.value.textarea,
			h = app.globalData.userId,
			m = ''
		console.log(u, mail, nssb, 'mail')
		if (/^[1][3,4,5,7,8][0-9]{9}$/.test(u) === false) m = '请输入正确的手机号码'
		else if (/^[0-9a-zA-Z]{15}|^[0-9a-zA-Z]{18}|^[0-9a-zA-Z]{20}$/.test(nssb) === false)
			m = '请输入正确的纳税人识别号'
		else if (/^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$/.test(mail) === false)
			m = '请输入正确的邮箱地址'
		'' == n
			? (m = '请输入企业名称')
			: '' == i
			? (m = '请选择地址')
			: '' == s
			? (m = '请输入联系人')
			: '' == mail
			? (m = '请输入邮箱')
			: '' == nssb
			? (m = '请输入纳税识别号')
			: '' == u
			? (m = '请输入电话')
			: '' == r && (r = ''),
			'' != m
				? wx.showModal({
						title: '',
						content: m
				  })
				: '' == m &&
				  (e.setData({
						store_num: 0
				  }),
				  app.util.request({
						url: 'entry/wxapp/FapiaoApply',
						cachetime: '0',
						data: {
							user_id: h,
							company: n,
							address: i,
							name: s,
							phone: u,
							order_id: e.data.order_id,
							money: e.data.money,
							mail: mail,
							nssb: nssb,
							other: r
						},
						success: function (t) {
							1 == t.data
								? (wx,
								  wx.showToast({
										title: '申请成功'
								  }),
								  setTimeout(function () {
										wx.navigateBack({
											delta: 2
										})
								  }, 1500))
								: wx.navigateBack({
										delta: 2
								  })
						},
						fail: function (t) {
							wx.showToast({
								title: '申请失败'
							}),
								setTimeout(function (t) {
									wx.navigateBack({
										delta: 2
									})
								}, 1500)
						}
				  }))
	}
})
